// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Emergent Game Technologies and may not 
// be copied or disclosed except in accordance with the terms of that 
// agreement.
//
//      Copyright (c) 1996-2007 Emergent Game Technologies.
//      All Rights Reserved.
//
// Emergent Game Technologies, Chapel Hill, North Carolina 27517
// http://www.emergent.net

#ifndef CEGUIGAMEBRYORENDERER_H
#define CEGUIGAMEBRYORENDERER_H

#include "CEGUIBase.h"
#include "CEGUIRenderer.h"
#include "CEGUITexture.h"

#include <NiMain.h>
#include <NiMeshScreenElements.h>

using namespace CEGUI;

class CEGUIGamebryoTexture;

/*!
\brief
	Renderer class to interface with Gamebryo
*/
class CEGUIGamebryoRenderer : public CEGUI::Renderer
{
public:
	CEGUIGamebryoRenderer(NiRenderer *pkGamebryoRenderer);
	virtual ~CEGUIGamebryoRenderer(void);

	// add's a quad to the list to be rendered
	virtual	void addQuad(const Rect& dest_rect, float z, const Texture* tex, 
		const Rect& texture_rect, const ColourRect& colours, 
		QuadSplitMode quad_split_mode);

	// perform final rendering for all queued renderable quads.
	virtual	void	doRender(void);

	// clear the queue
	virtual	void	clearRenderList(void);

	// create an empty texture
	virtual	Texture*	createTexture(void);

	// create a texture and load it with the specified file.
	virtual	Texture*	createTexture(const String& filename, 
		const String& resourceGroup);

	// create a texture and set it to the specified size
	virtual	Texture*	createTexture(float size);

	// destroy the given texture
	virtual	void		destroyTexture(Texture* texture);

	// destroy all textures still active
	virtual void		destroyAllTextures(void);

	virtual bool	isQueueingEnabled(void) const	{return m_bQueuing;}
	virtual void	setQueueingEnabled(bool setting) {m_bQueuing = setting;}
	virtual float	getWidth(void) const		
	{return (float)m_pkGamebryoRenderer->GetDefaultBackBuffer()->GetWidth();}
	virtual float	getHeight(void) const
	{return (float)m_pkGamebryoRenderer->GetDefaultBackBuffer()->GetHeight();}
	virtual Size	getSize(void) const			
	{return Size(getWidth(), getHeight());}
	virtual Rect	getRect(void) const	{return Rect(Point(0,0), getSize());}
	virtual	uint	getMaxTextureSize(void) const		{return 2048;}
	virtual	uint	getHorzScreenDPI(void) const	{return 96;}
	virtual	uint	getVertScreenDPI(void) const	{return 96;}
	void	setDisplaySize(const Size& sz);

private:
	NiTObjectSet<NiMeshScreenElementsPtr> m_kMeshScreenElementsSet;
	NiTPointerList<CEGUIGamebryoTexture*> m_kTextureList;
	unsigned int m_uiActiveElements;
	Texture *m_pkPreviousTexture;
	NiMeshScreenElementsPtr m_spImmediateElement;
	bool m_bQueuing;

	NiRenderer *m_pkGamebryoRenderer;
};

#endif	// CEGUIGAMEBRYORENDERER_H
